const USER_ID = 'userId'
const TOKEN = 'token'
const HISTORY_KEY = 'historyKeyWords'

// userId
function setUserId (value) {
  window.localStorage.setItem(USER_ID, value)
}

function getUserId () {
  return window.localStorage.getItem(USER_ID)
}

function removeUserId () {
  window.localStorage.removeItem(USER_ID)
}

// token
function setToken (token) {
  window.localStorage.setItem(TOKEN, token)
}
function getToken () {
  return window.localStorage.getItem(TOKEN)
}
function removeToken () {
  window.localStorage.removeItem(TOKEN)
}

// 历史记录
function setHistoryList (value) {
  window.localStorage.setItem(HISTORY_KEY, JSON.stringify(value))
}
function getHistoryList () {
  const historyList = window.localStorage.getItem(HISTORY_KEY)
  if (historyList) {
    return JSON.parse(historyList)
  }
  return ''
}
function removeHistoryList () {
  window.localStorage.removeItem(HISTORY_KEY)
}

export {
  setUserId,
  getUserId,
  removeUserId,
  setToken,
  getToken,
  removeToken,
  setHistoryList,
  getHistoryList,
  removeHistoryList
}
